mydat = rgdal::readOGR("./new_map/nynta.shp")
## OGR data source with driver: ESRI Shapefile 
## Source: "/Users/ada/Documents/Ada Documents/Master in Columbia/Courses/Data Science/R programming/homework/p8105_final_project/new_map/nynta.shp", layer: "nynta"
## with 195 features
## It has 7 fields
mydat2 = rgdal::readOGR("./new_map/nynta.shp")
## OGR data source with driver: ESRI Shapefile 
## Source: "/Users/ada/Documents/Ada Documents/Master in Columbia/Courses/Data Science/R programming/homework/p8105_final_project/new_map/nynta.shp", layer: "nynta"
## with 195 features
## It has 7 fields
summary(mydat2)
## Object of class SpatialPolygonsDataFrame
## Coordinates:
##        min       max
## x 913175.1 1067382.5
## y 120121.9  272844.3
## Is projected: TRUE 
## proj4string :
## [+proj=lcc +lat_1=40.66666666666666 +lat_2=41.03333333333333
## +lat_0=40.16666666666666 +lon_0=-74 +x_0=300000 +y_0=0
## +datum=NAD83 +units=us-ft +no_defs +ellps=GRS80 +towgs84=0,0,0]
## Data attributes:
##     BoroCode          BoroName  CountyFIPS    NTACode   
##  Min.   :1   Bronx        :38   005:38     BK09   :  1  
##  1st Qu.:2   Brooklyn     :51   047:51     BK17   :  1  
##  Median :3   Manhattan    :29   061:29     BK19   :  1  
##  Mean   :3   Queens       :58   081:58     BK21   :  1  
##  3rd Qu.:4   Staten Island:19   085:19     BK23   :  1  
##  Max.   :5                                 BK25   :  1  
##                                            (Other):189  
##                                        NTAName      Shape_Leng    
##  Airport                                   :  1   Min.   : 11000  
##  Allerton-Pelham Gardens                   :  1   1st Qu.: 23824  
##  Annadale-Huguenot-Prince's Bay-Eltingville:  1   Median : 30556  
##  Arden Heights                             :  1   Mean   : 42011  
##  Astoria                                   :  1   3rd Qu.: 41877  
##  Auburndale                                :  1   Max.   :490196  
##  (Other)                                   :189                   
##    Shape_Area       
##  Min.   :  5573902  
##  1st Qu.: 19383534  
##  Median : 32629789  
##  Mean   : 43230288  
##  3rd Qu.: 50237450  
##  Max.   :327760045  
## 
summary(mydat)
## Object of class SpatialPolygonsDataFrame
## Coordinates:
##        min       max
## x 913175.1 1067382.5
## y 120121.9  272844.3
## Is projected: TRUE 
## proj4string :
## [+proj=lcc +lat_1=40.66666666666666 +lat_2=41.03333333333333
## +lat_0=40.16666666666666 +lon_0=-74 +x_0=300000 +y_0=0
## +datum=NAD83 +units=us-ft +no_defs +ellps=GRS80 +towgs84=0,0,0]
## Data attributes:
##     BoroCode          BoroName  CountyFIPS    NTACode   
##  Min.   :1   Bronx        :38   005:38     BK09   :  1  
##  1st Qu.:2   Brooklyn     :51   047:51     BK17   :  1  
##  Median :3   Manhattan    :29   061:29     BK19   :  1  
##  Mean   :3   Queens       :58   081:58     BK21   :  1  
##  3rd Qu.:4   Staten Island:19   085:19     BK23   :  1  
##  Max.   :5                                 BK25   :  1  
##                                            (Other):189  
##                                        NTAName      Shape_Leng    
##  Airport                                   :  1   Min.   : 11000  
##  Allerton-Pelham Gardens                   :  1   1st Qu.: 23824  
##  Annadale-Huguenot-Prince's Bay-Eltingville:  1   Median : 30556  
##  Arden Heights                             :  1   Mean   : 42011  
##  Astoria                                   :  1   3rd Qu.: 41877  
##  Auburndale                                :  1   Max.   :490196  
##  (Other)                                   :189                   
##    Shape_Area       
##  Min.   :  5573902  
##  1st Qu.: 19383534  
##  Median : 32629789  
##  Mean   : 43230288  
##  3rd Qu.: 50237450  
##  Max.   :327760045  
## 
proj4string = "+proj=longlat +datum=NAD83 +no_defs +ellps=GRS80 +towgs84=0,0,0"

mydat2 = spTransform(mydat, proj4string)

uk

UK <- getData("GADM", country = "GB", level = 2)

### Create dummy data
set.seed(111)
mydf <- data.frame(place = unique(UK$NAME_2),
                   value = sample.int(n = 1000000, size = n_distinct(UK$NAME_2), replace = TRUE))

### Create five colors for fill
mypal <- colorQuantile(palette = "RdYlBu", domain = mydf$value, n = 5, reverse = TRUE)

leaflet() %>% 
addProviderTiles("OpenStreetMap.Mapnik") %>%
setView(lat = 55, lng = -3, zoom = 6) %>%
addPolygons(data = UK,
            stroke = FALSE, smoothFactor = 0.2, fillOpacity = 0.3,
            fillColor = ~mypal(mydf$value),
            popup = paste("Region: ", UK$NAME_2, "<br>",
                          "Value: ", mydf$value, "<br>")) %>%
addLegend(position = "bottomright", pal = mypal, values = mydf$value,
          title = "UK value",
          opacity = 1)

leaflet() %>% addTiles() %>% setView(lat = 40.7, lng = -74, zoom = 9) %>% addPolygons(data = mydat2, stroke = FALSE, smoothFactor = 0.2, fillOpacity = 0.3)

, fillColor = ~mypal(mydf\(value), popup = paste("Region: ", UK\)NAME_2, “
”, “Value:”, mydf\(value, "<br>")) %>% addLegend(position = "bottomright", pal = mypal, values = mydf\)value, title = “UK value”, opacity = 1)

pj <- project(mydat2, proj4string(MYDAT), inverse=TRUE) str(mydat)

mydat@coords print(proj4string(mydat)) fortify(mydat)

library(rgdal) sputm <- SpatialPoints(randompoints, proj4string=CRS(“+proj=utm +zone=??? +datum=WGS84”)
spgeo <- spTransform(sputm, CRS(“+proj=longlat +datum=WGS84”))

install.packages(“proj4”) library(proj4)

proj4string =proj4string(mydat)

proj4string <- “”+proj=utm +zone=19 +south +ellps=WGS84 +datum=WGS84 +units=m +no_defs “”

Source data

xy <- data.frame(x=986847.2, y = 223334.0)

Transformed data

pj <- project(xy, proj4string, inverse=TRUE) latlon <- data.frame(lat=pj\(y, lon=pj\)x) print(latlon)

coordinates(mydat) <- ~x+y

```